<template>
  <div>
    <el-form :inline="true" align="center">
      <el-form-item label="科室名称">
        <el-input
          type="text"
          :value="hospitalDept.deptname"
          v-model="hospitalDept.deptname"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-input
          type="text"
          :value="hospitalDept.deptcreatetime"
          v-model="hospitalDept.deptcreatetime" /></el-form-item
      ><br />
      <el-form-item>
        <el-button type="primary" @click="saveHospitalDept">保存</el-button>
        <el-button type="primary">
          <router-link to="/hospital/hospitalDeptList"
            >返回</router-link
          ></el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      hospitalDept: {},
    };
  },
  mounted() {
    var id = this.$route.params.id;
    this.$axios({
      url: `http://localhost:8080/jiapei/hos-dept/hospitalDept/${id}`,
      method: "GET",
    }).then((res) => {
      this.hospitalDept = res.data.data.hospitalDept;
    });
  },
  methods: {
    saveHospitalDept() {
      this.$axios({
        url: "http://localhost:8080/jiapei/hos-dept/hospitalDepts",
        method: "PUT",
        data: this.hospitalDept,
      }).then((res) => {
        if (res.data.code == 200) {
          this.$message({ message: res.data.message, type: "success" });
          this.$router.push("/hospital/hospitalDeptList");
        } else if (res.data.code == 209) {
          this.$message({ message: res.data.message, type: "warning" });
          this.$router.push("/hospital/hospitalDeptList");
        }
      });
    },
  },
};
</script>

<style>
</style>